<template>
  <TopNavBar title="返佣记录" type="back" />
  <div class="invite-detail-page">
    <!-- 顶部tab -->
    <div class="invite-tabs-bar">
      <div :class="['tab-btn', {active: tab==='invite'}]" @click="tab='invite'">邀請記錄</div>
      <div :class="['tab-btn', {active: tab==='rebate'}]" @click="tab='rebate'">返傭記錄</div>
    </div>
    <!-- 自定义下拉选择 -->
    <div class="invite-select-box" @click="toggleDropdown">
      <div class="invite-select-display">
        {{ currentSelectLabel }}
        <span class="invite-select-arrow">▼</span>
      </div>
      <div v-if="showDropdown" class="invite-dropdown">
        <div v-for="item in currentOptions" :key="item.value" class="invite-dropdown-item" @click.stop="selectOption(item)">
          {{ item.label }}
        </div>
      </div>
    </div>
    <!-- 邀请记录卡片 -->
    <div v-if="tab==='invite'" class="invite-list">
      <div v-if="rebateList.length === 0" class="empty-card">
		  <img class="empty-icon" src="/static/img/W2k_c7838bd9_spH.cd0c5744.png" alt="empty" />
		  <div class="empty-text">暫無參與紀錄</div>
        <!--<div class="invite-card-title">556677****6677</div>
        <div class="invite-card-time">2025-06-30 17:01:33</div>-->
      </div>
    </div>
    <!-- 返佣记录卡片（可后续补充） -->
    <div v-if="tab==='rebate'" class="invite-list">
      <div v-if="rebateList.length === 0" class="empty-card">
        <img class="empty-icon" src="/static/img/W2k_c7838bd9_spH.cd0c5744.png" alt="empty" />
        <div class="empty-text">暫無參與紀錄</div>
      </div>
      <div v-else>
        <div class="invite-card" v-for="item in rebateList" :key="item.id">
          <div class="invite-card-title">{{ item.title }}</div>
          <div class="invite-card-time">{{ item.time }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, watch } from 'vue'
import { getAgentInfo, getAgentList } from '@/api/plug.js'
import { _add, _div, _mul, priceFormat } from '@/utils/decimal'

const tab = ref('invite')
const showDropdown = ref(false)

// const ss = priceFormat(1.15734)
// console.log(ss)
// 邀请tab下拉
const inviteOptions = [
  { label: '所有會員', value: 'all' },
  { label: '1代會員', value: '1' },
  { label: '2代會員', value: '2' },
  { label: '3代會員', value: '3' },
]
// 返佣tab下拉
const rebateOptions = [
 // { label: 'CFD返傭', value: 'cfd' },
  { label: '充值返傭', value: 'recharge' },
 // { label: 'AI預測返傭', value: 'ai' },
 // { label: 'BOT策略返傭', value: 'bot' },
]
const selectValue = ref(inviteOptions[0].value)
const currentOptions = computed(() => tab.value === 'invite' ? inviteOptions : rebateOptions)
const currentSelectLabel = computed(() => {
  const found = currentOptions.value.find(i => i.value === selectValue.value)
  return found ? found.label : ''
})

watch(tab, (val) => {
  // 切tab时重置下拉选项
  selectValue.value = (val === 'invite' ? inviteOptions[0].value : rebateOptions[0].value)
  showDropdown.value = false
})

function toggleDropdown() {
  showDropdown.value = !showDropdown.value
}
function selectOption(item) {
  selectValue.value = item.value
  showDropdown.value = false
}
// 模拟返佣记录为空
const rebateList = ref([])
</script>

<style scoped lang="scss">
.invite-detail-page {
  min-height: 100vh;
  background: #f6f8fa;
  padding: 0 10px;
}
.invite-tabs-bar {
  display: flex;
  background: #f6f8fa;
  padding: 18px 0 10px 0;
  justify-content: center;
  gap: 0;
}
.tab-btn {
  flex: 1;
  text-align: center;
  font-size: 15px;
 // font-weight: bold;
  padding: 10px 0;
  border-radius: 30px;
  background: #fff;
  color: #000;
  margin: 0 0 0 0;
  transition: background 0.2s, color 0.2s;
}
.tab-btn.active {
	 font-size: 15px;
  background: #000;
  color: #fff;
  z-index: 999 !important;
}
.tab-btn:first-child {
  margin-right: -20px;
  z-index: 2;
}
.tab-btn:last-child {
  margin-left: -20px;
  z-index: 1;
}
.invite-select-box {
    margin: 8px 0 18px 0;
  width: 240px;
  max-width: 350px;
  position: relative;
  user-select: none;
}
.invite-select-display {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  background: #fff;
  font-size: 14px;
  color: #111;
  //font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  cursor: pointer;
  border: none;
  box-sizing: border-box;
}
.invite-select-arrow {
  margin-left: 8px;
  color: #222;
  font-size: 14px;
  //font-weight: bold;
}
.invite-dropdown {
  position: absolute;
  left: 0;
  top: 48px;
  width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  z-index: 10;
  padding: 18px 0 18px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.invite-dropdown-item {
  font-size: 14px;
  color: #111;
  //font-weight: bold;
  padding: 6px 0;
  width: 100%;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s;
}
.invite-dropdown-item:hover {
  background: #f6f8fa;
}
.invite-list {
  width: 100%;
  max-width: 400px;
}
.invite-card {
  background: #fff;
  border-radius: 12px;
  padding: 18px 16px 12px 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.invite-card-title {
  font-size: 20px;
  font-weight: bold;
  color: #000;
  margin-bottom: 6px;
}
.invite-card-time {
  font-size: 14px;
  color: #888;
}
.empty-card {
  width: 100%;
  min-height: 260px;
  background: #fff;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}
.empty-icon {
  width: 90px;
  height: 90px;
  margin: 40px 0 10px 0;
  display: block;
}
.empty-text {
  font-size: 14px;
  color: #222;
  //font-weight: bold;
  margin-bottom: 40px;
}
</style> 